<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/axios.min.js"></script>
    <script src="/js/util.js"></script>
    <script>
        window.onload = function () {
            findByItem(1)
        }
        function findByItem(pageNo) {
            axios.get("/user/findByItem",{
                params:{
                    pageNo,
                    account:$("account").value
                }
            }).then(e => {
                var info = e.data;
                var str = "";
                for (var i = 0;i < info.records.length;i++){
                    var obj = info.records[i];
                    str += `<tr>
                                <td>${obj.account}</td>
                                <td>${obj.name}</td>
                                <td>
                                    <input type="button" value="删除用户" onclick="delUser(${obj.id})">
                                    <a href="/user/update.html?id=${obj.id}">修改用户权限</a>
                                 </td>
                            </tr>`
                }
                $("userData").innerHTML = str;

                var pageStr = "";
                for (var i = 1;i <= info.pages;i++){
                    pageStr += `<a href="javascript:findByItem(${i})">${i}</a>`
                }
                $("cutPageDiv").innerHTML = pageStr;
            })
        }

        function delUser(id) {
            alert(id)
            axios.get("/user/del",{
                params: {
                    id
                }
            }).then(e => {
                if (e.data == "ok"){
                    location.href = "/user/user.html";
                }
            })
        }
    </script>
</head>
<body>
    <h2>用户管理</h2>
    <table border="1" width="90%">
        <thead>
            <tr>
                <th>用户名</th>
                <th>真实姓名</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody id="userData"></tbody>
    </table>
    <div style="margin: 20px" id="cutPageDiv"></div>
    <div style="display: flex">
        <div style="width: 300px">
            <a href="add.html">添加用户</a>
        </div>
        <div style="width: 300px">
            用户名：<input type="text" id="account">
            <input type="button" value="查询" onclick="findByItem(1)">
        </div>
    </div>
</body>
</html>